﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sasc.PV.BLL;
using Sasc.PV.DAL;
using Sasc.PV.Common.DEncrypt;

namespace Sasc.PV.Web.Admin.SystemManage
{
    public partial class SystemUserAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //设置上传的附件为空
                PublicMethod.SetSessionValue("WenJianList", "");
            }

        }
        //保存
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            //判断是否超过最大用户限制
            int AllowNum = 0;
            int NowNum = int.Parse(DbHelperSQL.GetSHSLInt("select count(*) from ERPUser"));
            try
            {
                AllowNum = int.Parse(DESEncrypt.Decrypt(DbHelperSQL.GetSHSL("select top 1 UserNum from ERPSerils"), "www.ework100.com"));
            }
            catch
            { }
            if (NowNum < AllowNum)
            {
                if (PublicMethod.IFExists("UserName", "ERPUser", 0, this.TextBox1.Text) == true)
                {
                    if (PublicMethod.IFExists("Serils", "ERPUser", 0, this.TextBox4.Text) == true)
                    {
                        ERPUser MyBuMen = new ERPUser();
                        MyBuMen.UserName = this.TextBox1.Text;
                        MyBuMen.UserPwd = DESEncrypt.Encrypt(this.TextBox2.Text);
                        MyBuMen.TrueName = this.TextBox3.Text;
                        MyBuMen.Serils = this.TextBox4.Text;
                        MyBuMen.Department = this.TextBox5.Text;
                        MyBuMen.JiaoSe = this.TextBox6.Text;
                        MyBuMen.ZhiWei = this.TextBox7.Text;
                        MyBuMen.ZaiGang = this.TextBox8.Text;
                        MyBuMen.EmailStr = this.TextBox9.Text;
                        MyBuMen.IfLogin = this.RadioButtonList1.SelectedItem.Text;
                        //MyBuMen.Sex = this.TextBox10.Text;
                        MyBuMen.BackInfo = this.TextBox11.Text;
                        //MyBuMen.BirthDay = this.TextBox12.Text;
                        // MyBuMen.MingZu = this.TextBox13.Text;
                        // MyBuMen.SFZSerils = this.TextBox14.Text;
                        //  MyBuMen.HunYing = this.TextBox15.Text;
                        // MyBuMen.ZhengZhiMianMao = this.TextBox16.Text;
                        // MyBuMen.JiGuan = this.TextBox17.Text;
                        // MyBuMen.HuKou = this.TextBox18.Text;
                        //MyBuMen.XueLi = this.TextBox19.Text;
                        // MyBuMen.ZhiCheng = this.TextBox20.Text;
                        // MyBuMen.BiYeYuanXiao = this.TextBox21.Text;
                        //MyBuMen.ZhuanYe = this.TextBox22.Text;
                        //    MyBuMen.CanJiaGongZuoTime = this.TextBox23.Text;
                        // MyBuMen.JiaRuBenDanWeiTime = this.TextBox24.Text;
                        MyBuMen.JiaTingDianHua = this.txtJiaTingDianHua.Text;
                        MyBuMen.Sex = this.DroSex.Text;
                        MyBuMen.ActiveTime = DateTime.Now;
                        // MyBuMen.Phone_home = this.txtPhone_home.Text;
                        // MyBuMen.Phone_work = this.txtPhone_work.Text;
                        //MyBuMen.JiaTingAddress = this.TextBox26.Text;
                        //MyBuMen.GangWeiBianDong = this.TextBox27.Text;
                        //MyBuMen.JiaoYueBeiJing = this.TextBox28.Text;
                        //MyBuMen.GongZuoJianLi = this.TextBox29.Text;
                        //MyBuMen.SheHuiGuanXi = this.TextBox30.Text;
                        //MyBuMen.JiangChengJiLu = this.TextBox31.Text;
                        //MyBuMen.ZhiWuQingKuang = this.TextBox32.Text;
                        //MyBuMen.PeiXunJiLu = this.TextBox33.Text;
                        //MyBuMen.DanBaoJiLu = this.TextBox34.Text;
                        //MyBuMen.NaoDongHeTong = this.TextBox35.Text;
                        //MyBuMen.SheBaoJiaoNa = this.TextBox36.Text;
                        //MyBuMen.TiJianJiLu = this.TextBox37.Text;
                        //MyBuMen.BeiZhuStr = this.TextBox38.Text;

                        MyBuMen.FuJian = PublicMethod.GetSessionValue("WenJianList");
                        MyBuMen.Add();
                        //写系统日志
                        ERPRiZhi MyRiZhi = new ERPRiZhi();
                        MyRiZhi.UserName = PublicMethod.GetSessionValue("UserName");
                        MyRiZhi.DoSomething = "用户添加新用户(" + this.TextBox1.Text + ")";
                        MyRiZhi.IpStr = System.Web.HttpContext.Current.Request.UserHostAddress.ToString();
                        MyRiZhi.Add();
                        MessageBox.ShowAndRedirect(this, "用户信息添加成功！", "SystemUser.aspx");
                    }
                    else
                    {
                        MessageBox.Show(this, "该用户编号已经存在，请更改其他用户编号！");
                    }
                }
                else
                {
                    MessageBox.Show(this, "该用户名已经存在，请更改其他用户名！");
                }
            }
            else
            {
                MessageBox.Show(this, "该系统已经达到最大允许用户数量，新用户信息不允许添加！");
            }
        }
    }
}